/*************************************************************************
	> File Name: B3623.cpp
	> Author: yufangze
	> Mail: 2224590123@qq.com
	> Created Time: 2025-01-10 11:37:04
 ************************************************************************/

#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int k, n;
int flag[15], ans[15];

void dfs(int x) {
    if (x == k + 1) {
        for (int i = 1; i <= k; i++) {
            cout << ans[i] << " ";
        }
        cout << endl;
        return ;
    }
    for (int i = 1; i <= n; i++) {
        if (flag[i]) continue;
        flag[i] = 1;
        ans[x] = i;
        dfs(x + 1);
        flag[i] = 0;
    }
    return ;
}

int main() {
    cin >> n >> k;
    dfs(1);
    return 0;
}
